package com.example.easydownloadback.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.easydownloadback.domin.FileType;
import com.example.easydownloadback.domin.ResponseResult;
import com.example.easydownloadback.service.FileTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/file_type")
public class FileTypeController {

    @Autowired
    private FileTypeService fileTypeService;

    /**
     * 获取文件类型列表，用于前端作为查询条件
     * @return
     */
    @GetMapping("/simple")
    public ResponseResult<List<Map<String, String>>> listSimpleFileType () {
        return fileTypeService.listSimpleFileType();
    }

    @GetMapping
    public ResponseResult<List<FileType>> listFileType () {
        return fileTypeService.listFileType();
    }
    @GetMapping("/{id}")
    public ResponseResult<List<String>> getFileTypeListByFileId (@PathVariable("id") String id) {
        return fileTypeService.getFileTypeListByFileId(id);
    }
    @PostMapping
    public ResponseResult addFileType(@RequestBody FileType fileType) {
        return fileTypeService.addFileType(fileType);
    }
    @GetMapping("/page")
    public ResponseResult<IPage<FileType>> listPageFileType(
            @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize,
            @RequestParam("selectValue") String selectValue) {
        return fileTypeService.listPageFileType(pageNum, pageSize, selectValue);
    }
    @DeleteMapping("/{id}")
    public ResponseResult deleteFileTypeById(@PathVariable("id") String id) {
        return fileTypeService.deleteFileTypeById(id);
    }
}
